package servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.MemberAdm;

@SuppressWarnings("serial")
public class RegisterServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.getRequestDispatcher("./index.jsp").forward(req, resp);
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		boolean addSuccess;
		req.setCharacterEncoding("BIG5");
		String userID = req.getParameter("userID");
		String password = req.getParameter("password");
		String name = req.getParameter("name");
		String phone = req.getParameter("phone");
		String address = req.getParameter("address");
		String email = req.getParameter("email");
		String coMemY = req.getParameter("coMemY");
		String coMemN = req.getParameter("coMemN");
		
		MemberAdm memAdm = new MemberAdm();
		addSuccess = memAdm.addMember(userID, password, name, phone, address, email, coMemY, coMemN);
		
		if(addSuccess)
			resp.sendRedirect("./index.jsp");
		else
			req.getRequestDispatcher("./member/registration.jsp").forward(req, resp);
	}
}
